
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * mysql to java type
 */
public final class MysqlTypeMapJavaType {
	 private final static Map map = new HashMap();
	 static{
		 map.put("VARCHAR", "String");
		 map.put("CHAR", "String");
		 map.put("BLOB", "byte[]");
		 map.put("TEXT", "String");
		 map.put("LONGTEXT", "String");
		 map.put("INTEGER", "Long");
		 map.put("TINYINT", "Integer");
		 map.put("INT", "Integer");
		 map.put("SMALLINT", "Integer");
		 map.put("MEDIUMINT", "Integer");
		 map.put("BIT", "Boolean");
		 map.put("BIGINT", "java.math.BigInteger");
		 map.put("FLOAT", "Float");
		 map.put("DOUBLE", "Double");
		 map.put("DECIMAL", "java.math.BigDecimal");
		 map.put("BOOLEAN", "Boolean");
		 map.put("BIGINT", "java.math.BigInteger");
		 map.put("ID", "Long");
		 map.put("DATE", "java.util.Date");
		 map.put("TIME", "java.util.Date");
		 map.put("DATETIME", "java.util.Date");
		 map.put("TIMESTAMP", "java.util.Date");
		 map.put("LONGBLOB", "byte[]");
		 
		 
	 }
	 public static String getJavaTypeFromMysqlType(String mysqlType,String defaultType){
		 Object obj=null;
		 if(defaultType==null){
			 obj= getJavaTypeFromMysqlType(mysqlType);
		 }else{
			 obj=map.get(mysqlType);
		 }
		 if(obj==null){
			 return  defaultType;
		 }else{
			 return String.valueOf(obj);
		 }
	 }
	 public static String getJavaTypeFromMysqlType(String mysqlType){
		 Object obj=map.get(mysqlType);
		 if(obj==null){
			 Set set =map.keySet();
			 Iterator it = set.iterator();
			 while(it.hasNext()){
				 String key = String.valueOf(it.next());
				 if(mysqlType.indexOf(key)!=-1){
					 obj=map.get(key);
				 }
			 }
		 }
		 if(obj==null){
			 return null;
		 }
		 return String.valueOf(obj);
	 }
}
